package com.nettm.leetcode;

public class PowerOfTwo231 {

    public static void main(String[] args) {
        PowerOfTwo231 p = new PowerOfTwo231();
        System.out.println(p.isPowerOfTwo(Integer.MAX_VALUE));
    }

    public boolean isPowerOfTwo(int n) {
        boolean result = false;
        if (n == 1) {
            return true;
        }

        while (n > 1) {
            if (n == 2) {
                result = true;
                break;
            } else if (n % 2 != 0) {
                break;
            } else {
                n = n / 2;
            }
        }
        return result;
    }

}
